package com.swt.dao.impl.S_impl;

import com.swt.dao.S_dao.GetVipCardDao;
import com.swt.domain.Course;
import com.swt.domain.Member;
import com.swt.domain.Shop;
import com.swt.domain.Vipcard;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository(value = "S_getVipCardDao")
public class GetVipCardDaoImpl implements GetVipCardDao {
    /*注入hibernateTemplate*/
    @Resource(name = "hibernateTemplate")
    private HibernateTemplate hibernateTemplate;
    @Override
    public List<Member> getVipCardDao(int id) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Member.class);
        detachedCriteria.add(Restrictions.eq("membershop",id));
        List<Member> list = ( List<Member>)hibernateTemplate.findByCriteria(detachedCriteria);
        return list;
    }

    @Override
    public Shop getClubById(int clubId) {
        Shop shop = hibernateTemplate.get(Shop.class, clubId);
        return shop;
    }

    @Override
    public Course getCourseByCourseId(int courseid) {
        Course course = hibernateTemplate.get(Course.class, courseid);
        return course;
    }

    @Override
    public List<Vipcard> getUseCard(int clubid, int userid,int bossid) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Vipcard.class);
        detachedCriteria.add(Restrictions.eq("vipcardBossid",bossid));
        detachedCriteria.add(Restrictions.eq("vipcardUserId",userid));
        detachedCriteria.add(Restrictions.eq("vipcardClub","0"));
        List<Vipcard> list = (List<Vipcard>)hibernateTemplate.findByCriteria(detachedCriteria);
        return list;
    }

    @Override
    public List<Vipcard> getAloneCard(int clubid, int userid) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Vipcard.class);
        detachedCriteria.add(Restrictions.eq("vipcardClubId",clubid));
        detachedCriteria.add(Restrictions.eq("vipcardClub","1"));
        List<Vipcard> list = (List<Vipcard>)hibernateTemplate.findByCriteria(detachedCriteria);
        return list;
    }
}
